//
//  GYXRefreshView.swift
//  RefreshControl
//
//  Created by Twisal on 2017/3/29.
//  Copyright © 2017年 Twisal. All rights reserved.
//

import UIKit

/// 刷新视图
class GYXRefreshView: UIView {
    /// 刷新状态
    var refreshState: GYXRefreshState = .Normal {
        didSet {
            switch refreshState {
            case .Normal:
                tipIcon?.isHidden = false
                indicator?.stopAnimating()
                tipLabel?.text = "继续使劲拉..."
                UIView.animate(withDuration: 0.25, animations: { 
                    self.tipIcon?.transform = CGAffineTransform.identity
                })
            case .Pulling:
            
                tipLabel?.text = "放手就刷新..."
                UIView.animate(withDuration: 0.25, animations: {
                    self.tipIcon?.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI - 0.001))
                })
            case .willRefresh:
                tipLabel?.text = "正在刷新中..."
                tipIcon?.isHidden = true
                indicator?.startAnimating()            }
        }
    }
    /// 标记图标
    @IBOutlet weak var tipIcon: UIImageView?
    
    /// 提示信息
    @IBOutlet weak var tipLabel: UILabel?

    /// 刷新指示器
    @IBOutlet weak var indicator: UIActivityIndicatorView?
    
    /// 视图高度
    var viewHeight: CGFloat = 0
    
    /// 刷新视图
    ///
    /// - Returns: 返回一个视图
    class func refreshView() -> GYXRefreshView {
        let nib = UINib(nibName: "GYXMeituanRefreshView", bundle: nil)
        return nib.instantiate(withOwner: nil, options: nil)[0] as! GYXRefreshView
    }
}
